package dpda;

import org.junit.jupiter.api.Test;
import pda.PDARule;

import java.util.Arrays;
import java.util.List;
import java.util.Set;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
 * @author haoly
 * @title PalindromesTest
 * @date 2025/4/22 09:10
 * @description 带中间标记的回文字符串测试
 */
public class PalindromesTest {
    @Test
    public void testAccepts() {
        List<PDARule<Integer>> rules = Arrays.asList(
                new PDARule<>(1, 'a', 1, '$', "a$"),
                new PDARule<>(1, 'a', 1, 'a', "aa"),
                new PDARule<>(1, 'a', 1, 'b', "ab"),
                new PDARule<>(1, 'b', 1, '$', "b$"),
                new PDARule<>(1, 'b', 1, 'b', "bb"),
                new PDARule<>(1, 'b', 1, 'a', "ba"),
                new PDARule<>(1, 'm', 2, '$', "$"),
                new PDARule<>(1, 'm', 2, 'a', "a"),
                new PDARule<>(1, 'm', 2, 'b', "b"),
                new PDARule<>(2, 'a', 2, 'a', ""),
                new PDARule<>(2, 'b', 2, 'b', ""),
                new PDARule<>(2, null, 3, '$', "$")
        );
        DPDARulebook<Integer> rulebook = new DPDARulebook<>(rules);
        DPDADesign<Integer> dpdaDesign = new DPDADesign<>(1, '$', Set.of(3), rulebook);
        assertTrue(dpdaDesign.accepts("abmba"));
        assertTrue(dpdaDesign.accepts("babbamabbab"));
        assertFalse(dpdaDesign.accepts("abmb"));
        assertFalse(dpdaDesign.accepts("baambaa"));
    }
}
